package com.tianya.forum.controller;

import com.tianya.forum.common.AppResult;
import com.tianya.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = "TestController 测试接⼝")
@RestController
@RequestMapping("/test")
public class TestController {


    @ApiOperation(value = "测试接⼝1，打印hello")
    @RequestMapping("/hello")
    public String test(){
        return "Hello, ====天涯论坛====";
    }


    @ApiOperation(value = "测试接⼝2，返回⼀个异常结果")
    @GetMapping("/exception")
    public String testException() throws Exception {
        throw new Exception("这是一个Exception。。。");
    }


    @ApiOperation(value = "测试接⼝3，返回⼀个⾃定义异常结果")
    @GetMapping("/appException")
    public String testApplication(){
        throw new ApplicationException("这是一个自定义的Application。。。");
    }

    // 注意：@ApiParam ⽅法参数的注解，⽤来描述参数
    @ApiOperation(value = "测试接⼝4，返回 你好+传⼊参数")
    @GetMapping("/helloByName")
    public AppResult<String> helloByName(@ApiParam(value = "名字", required =
            true) String name) {
        return AppResult.success("你好：" + name);
    }

}